home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / tclX-6.4 / help / control / proc < prev    next >
Encoding:
Text File  |  1992-12-17  |  3.1 KB  |  51 lines

  1.           proc name args body
  2.                The proc command creates a new Tcl  command  procedure,
  3.                name,  replacing  any  existing  command there may have
  4.                been  by  that  name.   Whenever  the  new  command  is
  5.                invoked,  the  contents of body will be executed by the
  6.                Tcl interpreter.  Args specifies the  formal  arguments
  7.                to  the  procedure.   It  consists  of a list, possibly
  8.                empty, each of whose elements specifies  one  argument.
  9.                Each  argument specifier is also a list with either one
  10.                or two fields.  If there is only a single field in  the
  11.                specifier,  then  it  is  the  name of the argument; if
  12.                there are two fields, then the first  is  the  argument
  13.                name  and  the second is its default value.  braces and
  14.                backslashes may be used in the  usual  way  to  specify
  15.                complex default values.
  16.  
  17.                When name is invoked, a local variable will be  created
  18.                for  each of the formal arguments to the procedure; its
  19.                value will be the value of  corresponding  argument  in
  20.                the  invoking  command or the argument's default value.
  21.                Arguments with default values need not be specified  in
  22.                a  procedure invocation.  However, there must be enough
  23.                actual arguments for  all  the  formal  arguments  that
  24.                don't  have  defaults,  and there must not be any extra
  25.                actual arguments.  There is one special case to  permit
  26.                procedures  with variable numbers of arguments.  If the
  27.                last formal argument has the name args, then a call  to
  28.                the  procedure  may  contain more actual arguments than
  29.                the procedure has formals.  In this case,  all  of  the
  30.                actual  arguments  starting  at  the  one that would be
  31.                assigned to args are combined into a list  (as  if  the
  32.                list  command  had  been  used); this combined value is
  33.                assigned to the local variable args.
  34.  
  35.                When body is being executed,  variable  names  normally
  36.                refer   to   local   variables,   which   are   created
  37.                automatically when  referenced  and  deleted  when  the
  38.                procedure returns.  One local variable is automatically
  39.                created for each of the procedure's arguments.   Global
  40.                variables  can  only be accessed by invoking the global
  41.                command.
  42.  
  43.                The proc command  returns  the  null  string.   When  a
  44.                procedure  is  invoked, the procedure's return value is
  45.                the value  specified  in  a  return  command.   If  the
  46.                procedure  doesn't execute an explicit return, then its
  47.                return value is the value of the last command  executed
  48.                in  the  procedure's  body.   If  an error occurs while
  49.                executing the procedure body, then the  procedure-as-a-
  50.                whole will return that same error.
  51.